<template>
  <div>
    <img src="../../assets/images/home.png">
  </div>
</template>

<script>
import { getExpire as getLbExpire, getAuditCount as getLbAuditCount } from '@/api/assets-lb';
import { getExpire as getZjExpire, getAuditCount as getZjAuditCount } from '@/api/assets-zj';

export default {
  name: 'Home',
  data() {
    return {
      lb: 0,
      zj: 0,
      lbAudit: 0,
      zjAudit: 0,
      notice1: null,
      notice2: null,
      notice3: null,
    };
  },
  computed: {
    role() {
      if (this.$store.state.user.role) {
        return this.$store.state.user.role.roleCode;
      }
      return '';
    },
  },
  async mounted() {
    const [zj, lbAudit, zjAudit] = await Promise.all([
      this.getZjExpire(), this.getLbAuditCount(), this.getZjAuditCount(),
    ]);
    // this.lb = lb.data;
    this.zj = zj.data;
    this.lbAudit = lbAudit.data;
    this.zjAudit = zjAudit.data;

    if (this.role === 'dandang') {
      // if (this.lb > 0) {
      //   await this.$notify({
      //     title: '提示',
      //     message: `您有${this.lb}个龙宝合同即将到期，请及时处理。`,
      //     position: 'bottom-right',
      //     duration: 0,
      //     onClick: () => {
      //       this.$router.push('/assets/assetsLb');
      //     },
      //   });
      // }
      if (this.zj > 0) {
        this.notice1 = await this.$notify({
          title: '提示',
          message: `您有${this.zj}条合同即将到期，请及时确认。`,
          position: 'bottom-right',
          duration: 0,
          onClick: () => {
            this.$router.push('/assets/assetsZj');
          },
        });
      }
    }
    if (this.zjAudit > 0) {
      this.notice2 = await this.$notify({
        title: '提示',
        message: `您有中介${this.zjAudit}项业务需要审核，请及时办理。`,
        position: 'bottom-right',
        duration: 0,
        onClick: () => {
          this.$router.push('/assets/assetsZj');
        },
      });
    }
    if (this.lbAudit > 0) {
      this.notice3 = await this.$notify({
        title: '提示',
        message: `您有龙宝${this.lbAudit}项业务需要办理，请及时确认。`,
        position: 'bottom-right',
        duration: 0,
        onClick: () => {
          this.$router.push('/assets/assetsLb');
        },
      });
    }
  },
  methods: {
    alert(text) {
      console.log(text);
    },
    getLbExpire() {
      return getLbExpire();
    },
    getZjExpire() {
      return getZjExpire();
    },
    getZjAuditCount() {
      return getZjAuditCount();
    },
    getLbAuditCount() {
      return getLbAuditCount();
    },
  },
  beforeDestroy() {
    if (this.notice1) {
      this.notice1.close();
    }
    if (this.notice2) {
      this.notice2.close();
    }
    if (this.notice3) {
      this.notice3.close();
    }
  },
};
</script>

<style scoped>
div {
  height: 100%;
  width: 100%;
  position: relative;
}
img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
